﻿//https://leetcode.cn/problems/happy-number/

class Solution {
public:
    int square_sum(int n)
    {
        int sum = 0;
        while (n)
        {
            int num = n % 10;
            sum += num * num;
            n /= 10;
        }
        return sum;
    }
    bool isHappy(int n)
    {
        //快慢指针法
        int slow = n;
        int fast = square_sum(n);
        while (slow != fast)
        {
            slow = square_sum(slow);
            fast = square_sum(square_sum(fast));
        }

        return slow == 1;

    }
};